
<script>
	$(function(){
	$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var name = $( "#memberName" ),
			allFields = $( [] ).add( name ),
			tips = $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		
		$( "#dialog-add" ).dialog({
			autoOpen: false,
			height: 520,
			width: 550,
			modal: true,
			buttons: {
				"新增": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );
					bValid = bValid && checkLength( name, "username", 2, 16 );
					if ( bValid ) {
						var username=$("#memberName").val();
						var remark=$("#remark").val();
						var status=$("#status").val();
						var time=$("#time").val();
						var id=$("#groupId").val();
						var displayStautus="";
						if(status=="忙碌")
                            displayStautus="<span><font color='#cc0001'>"+status+"&nbsp;</font><img src='images/high.jpg'/></span>";
                       else if(status=="正常")
                           displayStautus="<span><font color='#03cc02'>"+status+"&nbsp;</font><img src='images/normal.jpg'/></span>";
                       else if(status=="空闲")
                           displayStautus="<span><font color='#fb940b'>"+status+"&nbsp;</font><img src='images/low.jpg'/></span>";
                       else
                           displayStautus="<span><font color='#fb940b'>未知&nbsp;</font><img src='images/unknow.jpg'/></span>";
					
						$.ajax({
							url:"insert.php",
							type:"POST",
							data:"id="+id+"&username="+username+"&remark="+remark+"&status="+status+"&time="+time,
							success:function(data){
								if(data)
									{
									if(username.length<6)
										username=username+"&nbsp;&nbsp;&nbsp;";
									$("#accordion #main"+id+" span:last").append("</br><span><a disabled='true'><img src='images/user.png'/>"+username+"&nbsp;&nbsp;<img src='images/edit.png' alt='编辑成员' title='下次登录或者刷新页面编辑'/></a>&nbsp;&nbsp;"+"<img src='images/status2.png'/>"+displayStautus+"&nbsp;&nbsp;<img src='images/day.png'/>&nbsp;<font color='red'>1</font>/"+time+"天&nbsp;&nbsp;"+"<img src='images/task.png'/>&nbsp;"+remark+"&nbsp;&nbsp;</span></br>");
									$( "#dialog-add" ).dialog( "close" );
									}
								else{
									$( ".validateTips" ).text("新增成员失败!"); 
									}
								}
								});					
						
					}
				},
				"取            消": function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
$("#addMember").click(function(){
	$( "#dialog-add" ).dialog( "open" );
	return false;
	
});
		})
</script>
<?php
?>
<div id="dialog-add" title="新增小组成员">
	<fieldset>
		<input type="hidden" id="groupId"
			value="<?php if(isset($_SESSION["groupId"])) echo $_SESSION["groupId"];?>"
			name="id" /> <label>姓名:</label> <input type="text" id="memberName"
			name="username" class="text ui-widget-content ui-corner-all"
			autofocus="autofocus" /> <label>任务:</label>
		<textarea id="remark" name="remark" cols="43" rows='3'>见需求系统</textarea>
		</br>
		</br>状态: <select id="status" name="status">
			<option value="正常" selected='selected'>正常</option>
			<option value="忙碌">忙碌</option>
			<option value="空闲">空闲</option>
		</select></br>
		</br> 时间: <select id="time" name="time">
			<option value="1" selected='selected'>1</option>
    <?php
				for($i = 2; $i <= 7; $i ++) {
					echo "<option value ='" . $i . "'>" . $i . "</option>";
				}
				?>
    </select>&nbsp;(天)
		<!--   <input id="time" type="text"  name="time" value="3" maxlength="2" width="20" class="text ui-widget-content ui-corner-all" />-->
	</fieldset>
	<p class="validateTips">All form fields are required.</p>
</div>